package com.android.gpuimage;

import android.opengl.GLES20;

import com.android.av.GlUtil;


/**
 * Camera 的美颜滤镜第一步
 *
 */

public class BeautySub1Filter extends GPUImageFilter {

    private int mUTexMatrixLocation;
    private int mTexelWidthOffsetLocation;
    private int mTexelHeightOffsetLocation;
    private int mBrightnessLocation;

    private boolean mPositive;
    private float mBrightness;

    public BeautySub1Filter(int floor, int level) {
        this(floor, level, false, (float) (0.05 * level));
    }

    public BeautySub1Filter(int floor, int level, boolean positive, float brightness) {
        super(BeautyFilter.getVertexShader(floor, level),
                BeautyFilter.getFragmentShader2(floor, level, false));
        mPositive = positive;
        mBrightness = brightness;
    }

    @Override
    public void onInit() {
        super.onInit();
        mUTexMatrixLocation = GLES20.glGetUniformLocation(getProgram(), "uTexMatrix");
        mTexelWidthOffsetLocation = GLES20.glGetUniformLocation(getProgram(), "texelWidthOffset");
        mTexelHeightOffsetLocation = GLES20.glGetUniformLocation(getProgram(), "texelHeightOffset");
        mBrightnessLocation = GLES20.glGetUniformLocation(getProgram(), "brightness");
    }

    @Override
    public void onInitialized() {
        super.onInitialized();
        setUniformMatrix4f(mUTexMatrixLocation, GlUtil.IDENTITY_MATRIX);
        if (mPositive) {
            setFloat(mTexelWidthOffsetLocation, 0f);
            setFloat(mTexelHeightOffsetLocation, 0.0033333334f);
        } else {
            setFloat(mTexelWidthOffsetLocation, 0.0033333334f);
            setFloat(mTexelHeightOffsetLocation, 0f);
        }
        setFloat(mBrightnessLocation, mBrightness);
    }
}
